package javaVersion.learn.streamProcess;

import javaVersion.pojo.Pro3_Order;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;

import java.util.Random;
import java.util.UUID;

/**
 * @program: myFlink
 * @description: 自定义数据源
 * @author: WincoMa
 * @create: 2020-07-17 17:21
 **/
public class Pro3_MyRichSourceFunction extends RichSourceFunction<Pro3_Order> {

    @Override
    public void run(SourceContext<Pro3_Order> sourceContext) throws Exception {
        for (int i = 0; i < 100; i++) {
            String id = UUID.randomUUID().toString();
            Random random = new Random();
            String userId = random.nextInt(3) + "";
            int money = random.nextInt(101);
            long time = System.currentTimeMillis();
            sourceContext.collect(new Pro3_Order(id, userId, money, time));
            Thread.sleep(100);
//            TimeUnit.SECONDS.sleep(1);

        }
    }

    @Override
    public void cancel() {

    }
}